/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.core.api;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.PageList;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.EduStudent;
import com.xci.edu.core.entity.ExamPre;
import com.xci.edu.core.filter.EduStudentFilter;
import com.xci.edu.core.service.EduStudentService;
import com.github.lvyanyang.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 学员信息接口
 * @author 张谦 zhangqian@xci96716.com
 * @since 2020-11-24 15:29:29
 */
@Api(tags = "学员信息接口")
@Authorize
@RestController
@RequestMapping(value = "/api/core/eduStudent", produces = Const.PROJSON)
public class EduStudentApiController extends BaseController {
    /** 学员信息服务 */
    @Resource private EduStudentService eduStudentService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新建学员信息")
    @Authorize(code = "core.eduStudent.insert")
    @PostMapping("/insert")
    public BoolResult insert(@RequestBody EduStudent entity) {
        return eduStudentService.insert(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改学员信息")
    @Authorize(code = "core.eduStudent.update")
    @PostMapping("/update")
    public BoolResult update(@RequestBody EduStudent entity) {
        return eduStudentService.update(entity);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主键字符串删除学员信息")
    @Authorize(code = "core.eduStudent.delete")
    @PostMapping(value = "/delete")
    public BoolResult delete(@RequestBody IdsBody body) {
        return eduStudentService.delete(body.getIds());
    }

    //@ApiOperationSupport(order = 4)
    //@ApiOperation(value = "检查学员信息主键是否存在")
    //@PostMapping(value = "/existById")
    //public BoolResult existById(@RequestBody IdBody body) {
    //    return BoolResult.success(eduStudentService.existById(body.getId()));
    //}
    //@ApiOperationSupport(order = 5)
    //@ApiOperation(value = "检查学员信息名称是否存在")
    //@PostMapping(value = "/existByName")
    //public BoolResult existByName(@RequestBody NameExcludeIdBody body) {
    //    return BoolResult.success(eduStudentService.existByName(body.getName(), body.getExcludeId()));
    //}

    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "根据主键查询单个学员信息")
    @Authorize(code = "core.eduStudent.select")
    @PostMapping("/selectById")
    public BoolResult<EduStudent> selectById(@RequestBody IdBody body) {
        return BoolResult.success(eduStudentService.selectById(body.getId()));
    }

    @ApiOperationSupport(order = 9)
    @ApiOperation(value = "查询学员信息分页列表")
    @Authorize(code = "core.eduStudent.select")
    @PostMapping("/selectPageList")
    public BoolResult<PageList<EduStudent>> selectPageList(@RequestBody EduStudentFilter filter) {
        return BoolResult.success(eduStudentService.selectPageList(filter));
    }

    @ApiOperationSupport(order = 10, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "查询学员信息列表")
    @Authorize(code = "core.eduStudent.select")
    @PostMapping("/selectList")
    public BoolResult<List<EduStudent>> selectList(@RequestBody EduStudentFilter filter) {
        return BoolResult.success(eduStudentService.selectList(filter));
    }

    @ApiOperationSupport(order = 11, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "导出学员信息列表")
    @Authorize(code = "core.eduStudent.export")
    @PostMapping(value = "/export", produces = {Const.PROOCTET, Const.PROJSON})
    public void export(@RequestBody EduStudentFilter filter) {
        XCI.exportExcel(eduStudentService.selectList(filter), EduStudent.class, "学员信息列表");
    }

    @ApiOperationSupport(order = 12)
    @ApiOperation(value = "学生信息审核")
    @Authorize(code = "core.eduStudent.auditStudent")
    @PostMapping("/auditStudent")
    public BoolResult auditStudent(@RequestBody IdsBody body) {
        return eduStudentService.auditStudent(body.getIds());
    }

    @ApiOperationSupport(order = 13)
    @ApiOperation(value = "退档")
    @Authorize(code = "core.eduStudent.setStatusOne")
    @PostMapping("/setStatusOne")
    public BoolResult setStatusOne(@RequestBody IdsBody body) {
        return eduStudentService.setStatusOne(body.getIds());
    }

    @ApiOperationSupport(order = 14)
    @ApiOperation(value = "预约考试")
    @Authorize(code = "core.eduStudent.setExamPro")
    @PostMapping("/setExamProUpdate")
    public BoolResult setExamProUpdate(@RequestBody String ids,@RequestBody ExamPre examPreEntity) {
        return eduStudentService.setExamProUpdate(ids,examPreEntity);
    }

    //@ApiOperationSupport(order = 12)
    //@ApiOperation(value = "获取学员信息导出字段")
    //@PostMapping(value = "/exportNames")
    //public BoolResult<List<String>> exportNames() {
    //    return BoolResult.success(XCI.getExcelFiledNames(EduStudent.class));
    //}
}